<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML>
<html>
  <head>
    <title>大岭山中学网盘，让美好永远陪伴</title>

	<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,300' rel='stylesheet' type='text/css'>
	
	<link rel="stylesheet" href="static/css/bootstrap.min.css">
	<link rel="stylesheet" href="static/css/animate.css">
	<link rel="stylesheet" href="static/css/style.css">
	
	<style type="text/css">
		label.error{color:#ef392b;}
	</style>
	
  </head>
  
  <body class="style-3" onload="getCookie()">
    <div class="container">
		<div class="row">
			<div class="col-md-4 col-md-push-8">
				<form id="login" action="" class="fh5co-form animate-box" data-animate-effect="fadeInRight" onsubmit="return false;">
					<h2>登录大岭山中学网盘</h2>
					<div class="form-group">
						<input type="text" class="form-control" id="username" name="username" placeholder="用户名" autocomplete="off">
					</div>
					<div class="form-group">
						<input type="password" class="form-control" id="password" name="password" placeholder="密码" autocomplete="off">
					</div>
					<div class="form-group">
						<label for="remember"><input type="checkbox" id="remember"> 1周内记住我</label>
					</div>
					<div class="form-group">
						<p>还未注册? <a href="sign_up.jsp">立即注册</a> | <a href="forgot.jsp">忘记密码?</a></p>
					</div>
					<div class="form-group">
						<input type="submit" id="btnLogin" value="登录" class="btn btn-primary" onclick="login()">
					</div>
				</form>
			</div>
		</div>
	</div>
	<script src="static/jquery/1.9.1/jquery.min.js"></script>
	<script src="static/js/bootstrap.min.js"></script>
	<script src="static/js/jquery.placeholder.min.js"></script>
	<script src="static/js/jquery.waypoints.min.js"></script>
	<script src="static/js/main.js"></script>
	<script type="text/javascript" src="static/jquery.validation/1.14.0/jquery.validate.js"></script>
	<script type="text/javascript" src="static/jquery.validation/1.14.0/messages_zh.js"></script>
	<script type="text/javascript" src="static/js/jquery.cookie.js"></script>
	<script type="text/javascript" src="static/layer/2.4/layer.js"></script>
	<script type="text/javascript" src="static/js/jquery.base64.js"></script>
	
	<script type="text/javascript">
	
		$("body").bind("keypress",function(event){
			if(event.keyCode == 13){
				$("#btnLogin").click();
			}
		});
		
		function setCookie(){
			var user = $("#username").val();
			var pwd = $("#password").val();
			var checked = $("#remember").is(":checked");
			if(checked){
				if($.cookie("username") == null || $.cookie("username") != user || $.cookie("exit") == "exit"){
					$.cookie("username",user,{expires: 7,path:'/'});
				}
				if($.cookie("password") == null || $.base64.decode($.cookie("password")) != pwd || $.cookie("exit") == "exit"){
					$.cookie("password",$.base64.encode(pwd),{expires: 7,path:'/'});
				}
				$.cookie("exit",'',{expires: -1,path: "/"});
			}else {
				$.cookie("username",'',{expires: -1,path:'/'});
				$.cookie("password",'',{expires: -1,path:'/'});
			}
		}
		function getCookie(){
			var username = $.cookie("username");
			var password = $.cookie("password");
			var exit = $.cookie("exit");
			if(password){
				$("#remember").attr("checked","true");
				$("#password").val($.base64.decode(password));
			}
			
			if(exit){
				$("#remember").attr("checked","true");
			}
			
			if(username){
				$("#remember").attr("checked","true");
				$("#username").val(username);
			}
			
			if($("#username").val() != "" && $("#password").val() != "" && exit != "exit"){
				$("#btnLogin").click();
			}
		}
		
		function login(){
			if($("#remember").is(':checked')){
				setCookie();
			}else{
				$.cookie("username",'',{expires: -1,path:'/'});
				$.cookie("password",'',{expires: -1,path:'/'});
			}
		}
	</script>
	
	<script type="text/javascript">
		$(function(){
			$("#login").validate({
				onfocusout:function(element){
					$(element).valid();
				},
				rules:{
					username : {
						required: true
					},
					password : {
						required: true
					}
				},
				onkeyup:false,
				focusCleanup:false,
				success:"valid",
				submitHandler:function(){
					$.post("user/login.action",$("#login").serialize(),function(data){
						if(data.status == 0){
							window.location.href="${pageContext.request.contextPath}/index.action";
						}else if(data.msg == "账号或密码错误，请重新输入！"){
							layer.msg(data.msg,{icon: 5,time:3000});
							$("#password")[0].focus();
							$("#password").val("");
						}else {
							layer.msg(data.msg,{icon: 5,time:3000});
							$("#username")[0].focus();
						}
					})
				}
			});
		})
	</script>
	
  </body>
</html>
